package com.baturu.vin.gm.dto;

import com.baturu.vin.base.dto.BasePartsInfoDTO;
import com.baturu.vin.dto.EPCPartsImageDTO;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;


@Data
public class GMPartsDetailDTO extends BasePartsInfoDTO {
    private String partsCode;
    private String body;
    private String series;
    private String catalogCode;
    private String firstYear;
    private String lastYear;
    private String optionP;
    private String optionN;
    private String groupCode;
    private String groupDesc;
    private String pictureNO;
    private String subject;
    private String futurePart;
    private String quantity;
    private String kit;
    private String partNameCN;
    private String groupParam;
    private String hand;
    private String btrPartsName;
    private String mainGroup;
    private String subGroup;
    private List<EPCPartsImageDTO> epcPartsImageDTO;



    public void setPictureNO(String pictureNO) {
        if (StringUtils.isNumeric(pictureNO)) {
            pictureNO = String.valueOf(Integer.parseInt(pictureNO));
        }
        this.pictureNO = pictureNO;
    }

    public List<String> getOptionPList() {
        if (StringUtils.isNotBlank(optionP)) {
            return Arrays.asList(optionP.split(","));
        }
        return Collections.EMPTY_LIST;
    }

    public List<String> getOptionNList() {
        if (StringUtils.isNotBlank(optionN)) {
            return Arrays.asList(optionN.split(","));
        }
        return Collections.EMPTY_LIST;
    }

    public boolean containParts(List<GMPartsDetailDTO> detailDTOs){
        return detailDTOs.stream().anyMatch(detailDTO -> partsCode.equals(detailDTO.getPartsCode())
                && this.body.equals(detailDTO.getBody())
                && this.firstYear.equals(detailDTO.getFirstYear())
                && this.lastYear.equals(detailDTO.getLastYear())
                && this.partNameCN.equals(detailDTO.getPartNameCN())
                && this.hand.equals(detailDTO.getHand()));
    }
}
